local songwei = fk.CreateSkill{
  name = "hx__songwei",
  tags = { Skill.Lord },
}

Fk:loadTranslationTable{


  ["$hx__songwei1"] = "朕之玉言，可决万民生死！",
  ["$hx__songwei2"] = "受禅汉庭，德大可参日月！",
}

songwei:addEffect("active", {
  anim_type = "control",
  prompt = "#hx__songwei",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedEffectTimes(songwei.name, Player.HistoryGame) == 0 and
      table.find(Fk:currentRoom().alive_players, function(p)
        return p ~= player and p.kingdom == "wei"
      end)
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= player and to_select.kingdom == "wei"
  end,
  on_use = function(self, room, effect)
    local target = effect.tos[1]
    local skills = Fk.generals[target.general]:getSkillNameList(true)
    if target.deputyGeneral ~= "" then
      table.insertTableIfNeed(skills, Fk.generals[target.deputyGeneral]:getSkillNameList(true))
    end
    if #skills > 0 then
      room:handleAddLoseSkills(target, "-"..table.concat(skills, "|-"), nil, true, false)
    end
    room:setPlayerMark(target, "@@hx__songwei_target", 1)
  end,
})

songwei:addEffect(fk.EventPhaseStart, {
  can_trigger = function(self, event, target, player)
    return target == player and player:hasSkill(songwei.name) and player.phase == Player.Play and
      player:hasSkill("hx__xingshang", true) and player:getMark("@hx__xingshang_song") < 9 and
      table.find(player.room.alive_players, function(p)
        return p.kingdom == "wei" and p ~= player
      end)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player)
    local room = player.room
    local weiNum = #table.filter(room.alive_players, function(p)
      return p.kingdom == "wei" and p ~= player
    end)
    room:addPlayerMark(player, "@hx__xingshang_song", math.min(weiNum , 9 - player:getMark("@hx__xingshang_song")))
  end,
})

return songwei
